package output.store.view.base;

import output.store.view.base.Frame;

public class FrameStack
{
	public static Frame[] frames = new Frame[1000000];
	private static int frameCount = 0;
	private static int currentFrame = 0;
	
	public static void addFrame(String str)
	{
		Frame f = new Frame(str);
		frames[frameCount] = f;
		frameCount++;
	}
	
	public static int getFrame(double time)
	{
		if(time >= frames[frameCount-1].time)
		{
			if(time > frames[frameCount-1].time + 1)
			{
				currentFrame = 0;
				return -1;
			}
			else
			{
				currentFrame = frameCount-1;
				return currentFrame;
			}
		}
		else if(time > frames[currentFrame + 1].time)
		{
			while(time > frames[currentFrame + 1].time)
			{
				currentFrame++;
			}
			return currentFrame;
		}
		else
		{
			while(currentFrame > 0 && time < frames[currentFrame].time)
			{
				currentFrame--;
			}
			return currentFrame;
		}
	}
}